package servlet;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;


@SuppressWarnings("serial")
public class Cadastrar extends HttpServlet {
	
	@Override
	protected void doGet(HttpServletRequest request, 
						 HttpServletResponse response)
						 throws ServletException, IOException {
	
		HttpSession session = request.getSession();
		
		@SuppressWarnings("unchecked")
		ArrayList<Funcionario> lista = (ArrayList<Funcionario>) session.getAttribute("lista");
		if (lista == null) {
			lista = new ArrayList<Funcionario>();
			session.setAttribute("lista", lista);
		}
		
		Funcionario f = new Funcionario();
		
		f.setNome(request.getParameter("nome"));
		f.setMatricula(request.getParameter("matricula"));
		f.setSalario(request.getParameter("salario"));
		lista.add(f);
		
		session.setAttribute("lista", lista);
		
		
		RequestDispatcher dispatcher = request.getRequestDispatcher("gerar_tabela.jsp");
		dispatcher.forward(request, response);
	
	}
}
